/**
 * 
 */
package pl.kaczanowscy.tomek.ipdl.strategy;

import pl.kaczanowscy.tomek.ipdl.RoundResult;
import pl.kaczanowscy.tomek.ipdl.Strategy;
import pl.kaczanowscy.tomek.ipdl.enums.Move;

/**
 * GRIM - Grim Trigger.
 * 
 * @author Tomek Kaczanowski
 * 
 */
public final class GRIM implements Strategy {

	private boolean betrayed = false;

	/**
	 * GRIM plays cooperation until the first betrayal.
	 */
	@Override
	public Move getMove() {
		return (betrayed) ? Move.DEFECTION : Move.COOPERATION;
	}

	/**
	 * GRIM checks if opponent betrayed in the last round.
	 * 
	 * @see pl.kaczanowscy.tomek.ipdl.RoundListener#roundEnded(pl.kaczanowscy.tomek.ipdl.RoundResult)
	 */
	@Override
	public void roundEnded(RoundResult result) {
		if (Move.DEFECTION == result.getOpponentMove(this)) {
			betrayed = true;
		}
	}

}
